package com.gqj.bas.service.impl;

import com.gqj.bas.domain.BasProvider;
import com.gqj.bas.mapper.BasProviderMapper;
import com.gqj.bas.service.IBasProviderService;
import com.gqj.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 供应商信息Service业务层处理
 * 
 * @author lxq
 * @date 2023-12-17
 */
@Service
public class BasProviderServiceImpl implements IBasProviderService 
{
    @Autowired
    private BasProviderMapper basProviderMapper;

    /**
     * 查询供应商信息
     * 
     * @param providerId 供应商信息主键
     * @return 供应商信息
     */
    @Override
    public BasProvider selectBasProviderByProviderId(Long providerId)
    {
        return basProviderMapper.selectBasProviderByProviderId(providerId);
    }

    /**
     * 查询供应商信息列表
     * 
     * @param basProvider 供应商信息
     * @return 供应商信息
     */
    @Override
    public List<BasProvider> selectBasProviderList(BasProvider basProvider)
    {
        return basProviderMapper.selectBasProviderList(basProvider);
    }

    /**
     * 新增供应商信息
     * 
     * @param basProvider 供应商信息
     * @return 结果
     */
    @Override
    public int insertBasProvider(BasProvider basProvider)
    {
        basProvider.setCreateTime(DateUtils.getNowDate());
        return basProviderMapper.insertBasProvider(basProvider);
    }

    /**
     * 修改供应商信息
     * 
     * @param basProvider 供应商信息
     * @return 结果
     */
    @Override
    public int updateBasProvider(BasProvider basProvider)
    {
        basProvider.setUpdateTime(DateUtils.getNowDate());
        return basProviderMapper.updateBasProvider(basProvider);
    }

    /**
     * 批量删除供应商信息
     * 
     * @param providerIds 需要删除的供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteBasProviderByProviderIds(Long[] providerIds)
    {
        return basProviderMapper.deleteBasProviderByProviderIds(providerIds);
    }

    /**
     * 删除供应商信息信息
     * 
     * @param providerId 供应商信息主键
     * @return 结果
     */
    @Override
    public int deleteBasProviderByProviderId(Long providerId)
    {
        return basProviderMapper.deleteBasProviderByProviderId(providerId);
    }

    /**
     * 查询供应商是否被引用
     *
     * @param providerId 供应商ID
     * @return 结果 true 存在 false 不存在
     */
    @Override
    public boolean checkMaterialExistProvider(Long providerId) {
        int result = basProviderMapper.checkMaterialExistProvider(providerId);
        return result > 0;
    }

    /**
     * 查询供应商下拉框
     *
     * @param basProvider 供应商
     * @return 供应商集合
     */
    @Override
    public List<Map<String, Object>> providerOptions(BasProvider basProvider) {
        return basProviderMapper.providerOptions(basProvider);
    }
}
